#coding:utf-8

shopping_list= [['mac',9000],['book',30],['pad',2000],['phone',1500]]
shop_ka = []
saveing  = input('请出入您的金额：')
if saveing.isdigit():
    saveing=int(saveing)
    print('您的可用进去为%d元'%saveing)
    while True:
        for k,v in enumerate(shopping_list):
            print(k,'---->',v)
        shopping_code = input('请选择商品编码,"q"退出')

        if shopping_code.isdigit():
            shopping_code = int(shopping_code)
            shopping_momey = int(shopping_list[shopping_code][1])
            saveing = saveing - shopping_momey
            shop_ka.append([shopping_list[shopping_code][0],shopping_momey])
            print('您选择了%s，购买后余额为%d元'%(shopping_list[shopping_code][0],saveing))
        elif shopping_code == 'q':
            print('购买后余额为%d'%(saveing))
            print('您购买的商品为：',shop_ka)
            break
        else:
            print('请输入合法的商品编码')

else:
    print('请输入合法金额')